package com.wye.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wye.dao.CategoryMapper;
import com.wye.dao.SpecMapper;
import com.wye.goods.pojo.Category;
import com.wye.goods.pojo.Goods;
import com.wye.goods.pojo.Spec;
import com.wye.goods.pojo.Spu;
import com.wye.service.SpecService;
import entity.IdWorker;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecServiceImpl implements SpecService {

    private static Logger logger = LoggerFactory.getLogger(SpecServiceImpl.class);

    @Autowired
    private SpecMapper specMapper;

    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public List<Spec> findByCategoryId(Integer categoryId) {
        Category category = categoryMapper.selectByPrimaryKey(categoryId);
        return specMapper.findByCategoryId(category.getTemplateId());
    }

    @Override
    public List<Spec> findAll() {
        return specMapper.selectAll();
    }

    @Override
    public Spec findById(Integer id) {
        if (id != null){
            return specMapper.selectByPrimaryKey(id);
        }
        return null;
    }

    @Override
    public int insert(Spec spec) {
        return specMapper.insertSelective(spec);
    }

    @Override
    public void update(Spec spec) {
        specMapper.updateByPrimaryKeySelective(spec);
    }

    @Override
    public void delete(Integer id) {
        specMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Spec> findList(Spec spec) {
        return specMapper.selectAll();
    }


    @Override
    public PageInfo<Spec> findPage(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Spec> SpecList = specMapper.selectAll();
        //封装PageInfo
        return new PageInfo<>(SpecList);
    }

   


}
